package com.fudan.framework.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fudan.framework.entity.RequestEntity;
import com.fudan.framework.entity.ResponseMsg;

/**
 * 查询的接口
 * @author Xuxinxing
 *
 * @param <T>
 */
public interface FindController<T extends RequestEntity> extends FunctionalController<T>{
    @RequestMapping("/find")
    @ResponseBody
    default public ResponseMsg doFind(HttpServletRequest request) {
        checkPermission("find");
        T find = find(request);
        if(find != null) {
        	return ResponseMsg.build(SUCCESS_CODE).put("data",find );
        }else {
        	return ResponseMsg.build(404);
        }
    }

    default public T find(HttpServletRequest request) {
        String id = request.getParameter("id");
        return injectService().get(id);
    }
}
